//
//  emptyView.swift
//  todoList
//
//  Created by Aoyun on 06/01/2025.
//

import SwiftUI

struct emptyView: View {
    @State private var animate: Bool = false
    var body: some View {
        ScrollView {
            VStack(spacing: 10) {
                Text("There are no items!")
                    .font(/*@START_MENU_TOKEN@*/ .title/*@END_MENU_TOKEN@*/)
                    .fontWeight(.semibold)
                Text("click the add button and add a bunch of items to your todom list!").padding(.bottom, 10)
                NavigationLink(destination: addTodoView(), 
                label: {
                    Text("Add Something")
                        .foregroundColor(.white)
                        .font(.headline)
                        .frame(maxWidth: .infinity)
                        .frame(height: 50)
                        .background(animate ? Color.orange : Color.blue)
                        .cornerRadius(15)
                }).padding(.horizontal, animate ? 30 : 50)
                    .shadow(
                        color: animate ?Color.orange.opacity(0.7) : Color.blue.opacity(0.7),
                        radius: animate ? 30 : 10,
                        x: 0,
                        y: animate ? 50 : 30)
                    .scaleEffect(animate ? 1.1 : 1.0)
                    .offset(y: animate ? -7 : 0)
                    .frame(maxWidth: 400)
            }.multilineTextAlignment(.center)
                .padding(40)
                .navigationTitle("Title")
                .onAppear(perform: {
                    changeAnimate()
                })
        }.frame(maxWidth: .infinity, maxHeight: .infinity)
    }

    func changeAnimate() {
        guard !animate else { return }
        DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
            withAnimation(
                Animation.easeInOut(duration: 2.0).repeatForever()
            ) {
                animate.toggle()
            }
        }
    }
}

#Preview {
    NavigationStack {
        emptyView()
    }
}
